module DevWisdom
  module View
      ROUNDED = false
      def check_list(objeck, fld, mthd, ldata, ul_id, ul_class)
        rvalue = %(<ul id="#{ul_id}" class="#{ul_class}">)
        i = 0
        for d in ldata
          bg = row_class(i)
          i += 1
          checked = object.send( mthd(d[fld]) )
          rvalue << checklist_li(d.name, "grp", grp.id, bg, checked)
        end
        rvalue << %(</ul>)
      end
      
      def checklist_li(label,name,id,cls,checked)
        ref = name + "_" + id.to_s
        ckd = "checked" if checked
        return <<-LI
          <li class="#{cls}">
            <label for="#{ref}">
              <input id="#{ref}" name="#{ref}" type="checkbox" #{ckd}/>&nbsp;&nbsp;#{label}
            </label>
          </li>
        LI
      end
      
      def data_list(ldata, fld, apind = "")
        rvalue = ""
        ldata.each{|d| rvalue <<  d.send(fld) << apind}
        rvalue
      end

      def row_class(i)
        ( i % 2 == 0 ) ? "even" : "odd"
      end
      
      def start_tiny_wrapper(title)
        rvalue = start_tiny_div_wrapper(ROUNDED)
        rvalue << %(<h3>#{title}</h3><div id="tiny">)
        rvalue
      end
      
      def start_small_wrapper(title)
        rvalue = start_small_div_wrapper(ROUNDED)
        rvalue << %(<h3>#{title}</h3><div id="small">)
        rvalue
      end
      
      def start_medium_wrapper(title)
        rvalue = start_medium_div_wrapper(ROUNDED)
        rvalue << %(<h3>#{title}</h3><div id="medium">)
        rvalue
      end
      
      def start_large_wrapper(title)
        rvalue = start_large_div_wrapper(ROUNDED)
        rvalue << %(<h3>#{title}</h3><div id="large">)
        rvalue
      end
      
      def end_wrapper
        rvalue = %(</div>)
        rvalue << end_div_wrapper(ROUNDED)
        rvalue
      end
      
      def start_tiny_div_wrapper(round = false)
        rvalue = ""
        rvalue << top_round("tiny_round_wrapper","spiffy_div_top") if round
        rvalue << "<div id=\"tiny_wrapper\">"
        rvalue
      end

      def start_small_div_wrapper(round = false)
        rvalue = ""
        rvalue << top_round("small_round_wrapper","spiffy_div_top") if round
        rvalue << "<div id=\"small_wrapper\">"
        rvalue
      end

      def start_medium_div_wrapper(round = false)
        rvalue = ""
        rvalue << top_round("medium_round_wrapper","spiffy_div_top") if round
        rvalue << "<div id=\"medium_wrapper\">"
        rvalue
      end

      def start_large_div_wrapper(round = false)
        rvalue = ""
        rvalue << top_round("large_round_wrapper","spiffy_div_top") if round
        rvalue << "<div id=\"large_wrapper\">"
        rvalue
      end

      def end_div_wrapper(round = false)
        rvalue = ""
        rvalue << "</div>"
        rvalue << bottom_round("spiffy_div_bottom") if round
        rvalue
      end

      def top_round(div_klass,spiffy_klass,is_class = false)
        div_type = "id"
        div_type ="class" if is_class
        return <<-ROUND
          <div #{div_type}="#{div_klass}">
            <b class="#{spiffy_klass}">
              <b class="spiffy1"><b></b></b>
              <b class="spiffy2"><b></b></b>
              <b class="spiffy3"></b>
              <b class="spiffy4"></b>
              <b class="spiffy5"></b>
            </b>
        ROUND
      end

      def bottom_round(spiffy_klass)
        return <<-ROUND
          <b class="#{spiffy_klass}">
            <b class="spiffy5"></b>
            <b class="spiffy4"></b>
            <b class="spiffy3"></b>
            <b class="spiffy2"><b></b></b>
            <b class="spiffy1"><b></b></b>
          </b>
        </div>
        ROUND
      end
  end # end View module
end # end DevWidsom module

ActionView::Base.send :include, DevWisdom::View
